package csu.web.credit_bank.controller;

import csu.web.credit_bank.service.ImageService;
import csu.web.credit_bank.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/images")
public class ImageController {
    @Autowired
    private ImageService imageService;
    @PostMapping("/upload")
    public Result<String> uploadImage(@RequestParam("file") MultipartFile file) {
        try {
            String imageUrl = imageService.saveImage(file); // 返回的是文件名
            return Result.success("图片上传成功", imageUrl);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.failure("图片上传失败: " + e.getMessage());
        }
    }
}